import { addHospitaSet } from '@/api/hospital/hospitalSet';
import { Button, Card, Form, Input, Space, message } from 'antd'
import React from 'react'
import { useNavigate } from 'react-router-dom';

export default function AddOrUpdate() {
    // 创建form对象
    const [form] = Form.useForm();
    // navigate
    const navigate = useNavigate();
    const onFinish = async () => {
        let data = form.getFieldsValue();
        try {
            // 发送请求添加医院设置
            await addHospitaSet(data);
            // 提示成功信息
            message.success('添加成功');
            // 跳转到医院设置列表
            navigate('/syt/hospital/hospitalSet');
        }catch(e:any){
            message.error(e.message)
        }
    }
    return (
        <Card>
            <Form
                form={form}
                name="basic"
                labelCol={{ span: 2 }}
                wrapperCol={{ span: 22 }}
                onFinish={onFinish}
            >
                <Form.Item
                    label="医院名称"
                    name="hosname"
                    rules={[{ required: true, message: '请添加医院名称!' }]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="医院编号"
                    name="hoscode"
                    rules={[{ required: true, message: '请填写医院编号!' }]}
                >
                    <Input />
                </Form.Item>

                <Form.Item
                    label="api基础路径"
                    name="apiUrl"
                    rules={[{ required: true, message: '请填写医院编号!' }]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="联系人姓名"
                    name="contactsName"
                    rules={[{ required: true, message: '请填写医院编号!' }]}
                >
                    <Input />
                </Form.Item>
                <Form.Item
                    label="联系人手机"
                    name="contactsPhone"
                    rules={[{ required: true, message: '请填写医院编号!' }]}
                >
                    <Input />
                </Form.Item>
                <Form.Item wrapperCol={{ offset: 2, span: 16 }}>
                    <Space>
                        <Button type="primary" htmlType="submit">
                            保存
                        </Button>
                        <Button htmlType="submit">
                            返回
                        </Button>
                    </Space>
                </Form.Item>
            </Form>
        </Card>
    )
}
